package com.fita.admin.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.coupon.Coupon;
import com.fita.entity.coupon.CouponBatch;
import com.fita.entity.coupon.CouponStatus;
import com.fita.entity.coupon.CouponTemplate;
import com.fita.entity.coupon.stat.CouponTemplateStat;
import com.fita.entity.order.Order;

import java.util.List;
/**
 * 
 * @author LZJ
 *
 */
@Dao("hibernate")
public interface CouponDao {

       
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CouponTemplate WHERE disabled = false ORDER BY createTime ASC")
    public List<CouponTemplate> listCouponTemplate(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CouponBatch WHERE credit = false ORDER BY createTime ASC")
    public List<CouponBatch> listCouponBatch(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param couponBatch
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Coupon WHERE batch = :batch ORDER BY id ASC")
    public List<Coupon> listCoupon(@Variable("batch") CouponBatch couponBatch,@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param id
     * @return
     */
    @Query("FROM CouponTemplateStat couponTemplateStat WHERE couponTemplateStat.id = :id")
    public CouponTemplateStat getCouponTemplateStat(@Variable("id") Long id);
    
    /**
     * 
     * @param couponTemplate
     * @return
     */
    @Query("FROM CouponBatch WHERE couponTemplate = :couponTemplate")
    public CouponBatch getCouponBatch(@Variable("couponTemplate") CouponTemplate couponTemplate);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM Coupon WHERE code = :code")
    public Coupon load(@Variable("code") String code);
    

    @Query("FROM Coupon WHERE order = :order")
    public List<Coupon> listCouponsByOrder(@Variable("order")Order order);
    
    @Query("FROM Coupon WHERE status = :status  and template.id = :templateId")
    public Coupon loadSingleCoupon(@Variable("status") CouponStatus status,@Variable("templateId") Long templateId);
    
    @Limit
    @Query("FROM Coupon WHERE status = :status  and template.id = :templateId")
    public List<Coupon> loadManyCoupon(@Variable("status") CouponStatus status,@Variable("templateId") Long templateId,@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    @Limit
    @Query("FROM Coupon WHERE status = :status")
    public List<Coupon> listAllUseCoupons(@Variable("status") CouponStatus status,@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

}
